<template>
  <div class="pay-main">
    <div class="pay-container">
      <div class="checkout-tit">
        <h1 class="tit-txt">请选择付款方式</h1>
        <div class="paymark">
          <span class="fl">交易号：xxxxxxxaaad11111<em></em></span>
          <span class="fr"
            ><em class="lead">实付金额：</em
            ><em class="orange money">￥{{ total }}</em></span
          >
        </div>
      </div>
      <div class="checkout-steps">
        <div class="step-tit">
          <span>支付方式:</span>
        </div>
        <div class="step-cont">
          <ul class="payType">
            <li><img src="./images/pay4.jpg" /></li>
            <li><img src="./images/pay2.jpg" /></li>
            <li @click="payHandle"><img src="./images/pay3.jpg" /></li>
          </ul>
        </div>
        <div class="hr"></div>
        <div class="hr"></div>

        <div class="submit">
          <el-button type="text" class="btn" @click="goHome">下一步</el-button>
          <el-dialog
            title="扫一扫付款"
            :visible.sync="dialogVisible"
            width="20%"
          >
            <div>
              <img :src="qrcode" width="192" />
            </div>
            <span slot="footer" class="dialog-footer">
              <el-button @click="dialogVisible = false">取 消</el-button>
              <el-button type="primary" @click="dialogVisible = false"
                >确 定</el-button
              >
            </span>
          </el-dialog>
          <el-dialog
            title="付款成功~即将返回首页"
            :visible.sync="visible"
            width="20%"
          >
            <span slot="footer" class="dialog-footer">
              <el-button type="primary" @click="$router.push({ name: 'Home' })"
                >确 定</el-button
              >
            </span>
          </el-dialog>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// // 引入二维码
import QRCode from "qrcode";
export default {
  name: "Topay",
  data() {
    return {
      visible: false,
      imgUrl: "",
      qrcode: "",
      dialogVisible: false,
      total: 0,
    };
  },
  mounted() {
    const { total } = this.$route.query;
    this.total = total;
    this.setQRCode("http://127.0.0.1");
  },
  methods: {
    // 根据字符串生成二维码
    setQRCode(str) {
      QRCode.toDataURL(str, { width: 192, margin: 1 }).then((res) => {
        // toDataURL方法返回一个promise
        this.qrcode = res;
      });
    },
    // 付款
    payHandle() {
      this.dialogVisible = true;
    },
    goHome() {
      this.visible = true;
    },
  },
};
</script>

<style lang="less" scoped>
.pay-main {
  margin-bottom: 20px;

  .pay-container {
    margin: 0 auto;
    width: 1090px;

    a:hover {
      color: #4cb9fc;
    }

    .orange {
      color: #e1251b;
    }

    .money {
      font-size: 18px;
    }

    .zfb {
      color: #e1251b;
      font-weight: 700;
    }

    .checkout-tit {
      padding: 10px;

      .tit-txt {
        font-size: 17px;
        line-height: 21px;

        .success-icon {
          width: 30px;
          height: 30px;
          display: inline-block;
          background: url(./images/icon.png) no-repeat 0 0;
        }

        .success-info {
          padding: 0 8px;
          line-height: 30px;
          vertical-align: top;
        }
      }

      .paymark {
        overflow: hidden;
        line-height: 26px;
        padding: 5px 0px;
        // text-indent: 38px;

        .fl {
          // float: left;
          font-size: 16px;
          color: #999 !important;
        }

        .fr {
          float: right;

          .lead {
            margin-bottom: 18px;
            font-size: 15px;
            font-weight: 400;
            line-height: 22.5px;
          }
        }
      }
    }

    .checkout-info {
      padding-left: 25px;
      padding-bottom: 15px;
      margin-bottom: 10px;
      border: 2px solid #e1251b;

      h4 {
        margin: 9px 0;
        font-size: 14px;
        line-height: 21px;
        color: #e1251b;
      }

      ol {
        padding-left: 25px;
        list-style-type: decimal;
        line-height: 24px;
        font-size: 14px;
      }

      ul {
        padding-left: 25px;
        list-style-type: disc;
        line-height: 24px;
        font-size: 14px;
      }
    }

    .checkout-steps {
      margin-top: 20px;
      border: 1px solid #ddd;
      // padding: 0px 25px;

      .hr {
        height: 1px;
        background-color: #ddd;
      }

      .step-tit {
        box-sizing: border-box;
        height: 42px;
        width: 1090px;
        background-color: #f4f4f4;
        border-bottom: 1px solid #efefef;
        line-height: 41px;
        color: #999;
        font-size: 14px;
      }

      .step-cont {
        margin: 30px 0px;

        ul {
          font-size: 0;

          li {
            margin: 0px 30px;
            display: inline-block;
            padding: 5px 20px;
            border: 1px solid #ddd;
            cursor: pointer;
            line-height: 18px;
          }
        }
      }
    }

    .submit {
      position: relative;
      margin-top: 40px;
      text-align: right;
      height: 100px;

      .btn {
        position: absolute;
        right: 0px;
        margin-top: 15px;
        position: absolute;
        height: 50px;
        line-height: 30px;
        width: 168px;
        font-size: 16px;
        color: #fff;
        border: 1px solid #b4a078;
        background-color: #b4a078;
      }
    }
  }
}
.btn-wrap {
  float: right;
}
.btnbox {
  padding: 5px 7px;
  outline: none;
  border: none;
  border-radius: 3px;
  width: 50px;
  height: 30px;
  margin: 0px 5px;
  cursor: pointer;
  &.primary {
    background-color: rgb(28, 170, 218);
    color: #fff;
  }
}
.QRimg {
  display: block;
  margin: 0px auto;
}
</style>